package com.big.merchan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.big.common.exception.BigException;
import com.big.common.result.ResultCodeEnum;
import com.big.merchan.mapper.MerchandisePhotoCordMapper;
import com.big.merchan.service.MerchandisePhotoCordService;
import com.big.model.model.merchandise.MerchandisePhotoCord;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MerchandisePhotoCordServiceImpl extends ServiceImpl<MerchandisePhotoCordMapper, MerchandisePhotoCord> implements MerchandisePhotoCordService {



    @Override
    public List<MerchandisePhotoCord> merchandisePhotoCordInfos(String mId) {
        QueryWrapper<MerchandisePhotoCord> queryWrapper =new QueryWrapper<>();
         if(!StringUtils.isEmpty(mId)){
              queryWrapper.eq("m_id",mId);
         }else {
             throw  new BigException(ResultCodeEnum.DATA_ERROR);
         }
//        queryWrapper.eq("is_deleted",0);
        List<MerchandisePhotoCord> merchandisePhotoCords = baseMapper.selectList(queryWrapper);
        return merchandisePhotoCords;
    }

    @Override
    public Integer SavePhotoCord(List<MerchandisePhotoCord> photoCords) {
        Integer io=0;
        for (int i = 0; i < photoCords.size(); i++) {
            baseMapper.insert(photoCords.get(i));
            io++;
        }
        if(io!=photoCords.size()){
            throw  new BigException(ResultCodeEnum.DATA_ERROR);
        }
        return io;
    }


}
